<%@ taglib uri="/WEB-INF/lattice.tld" prefix="lattice"%>

<%@ page import="java.util.Properties" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="org.mitre.mrald.util.Config" %>
<%@ page import="org.mitre.lattice.custom.LatticeFactory" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

  <head>
    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <meta name="latticeServer" content="HTML Tidy, see www.w3.org">
    <title>
      Lattice Preferences
    </title>
    <%=Config.getProperty( "CSS" ) %>
    <link href="test.css" type="text/css" rel="stylesheet">

  <script type="text/javascript">

  <%
    LatticeFactory latticeFactory = Config.getLatticeFactory();
   
    String[] nodeTypes =latticeFactory.getConstants().getNodeTypes();
    int typeCount = nodeTypes.length;

     Properties props =latticeFactory.getProperties();
    Iterator keys = (Iterator)props.propertyNames();
    
    for (int i = 0; i < typeCount; i++ ) {
         int j = i*2;
    %>
        
       <%
       }
       %>

       function openChild(file,window, test) {
       childWindow=open(file,window,'width=400,height=310,status=yes,scrollbars=yes,toolbar=yes,resizable');
        if (childWindow.opener == null) childWindow.opener = self;
	
       }
       
       function updateValues() {
       
             <%
	       for (int i = 0; i < typeCount; i++ ) {
               int j = i*2;
	       %>
             document.getElementById('<%=nodeTypes[i] + "ColorStartValueID"%>').value = document.getElementById('<%=nodeTypes[i] + "ColorStartID"%>').style.backgroundColor
	     document.getElementById('<%=nodeTypes[i] + "ColorEndValueID"%>').value = document.getElementById('<%=nodeTypes[i] + "ColorEndID"%>').style.backgroundColor
	     <% } %>
	}
	
        function setId(id)
	{
            document.forms[0].idValue.value = id
       }
       </script>
  </head>
  
  <body>
    <form ENCTYPE="x-www-form-urlencoded" ACTION="UpdatePrefs.jsp" METHOD="POST" target="_parent" onsubmit="return updateValues( this )">
    <center>
    <table cellpadding="0" cellspacing="0" border="0" >
        <tr>
          <td class="bord">
	      
              <table cellpadding="5" cellspacing="1" border="0" >
                <tr>
                  <th class="title" COLSPAN="3">
                    Node Types
                  </th>
                </tr>
                <tr>
                  <td colspan="3">
                    <b>List Node Types</b>
		  </td>
                </tr>
		<tr>
		<th>Node Type</th>
		<th width="45">Start Color</th>
		<th width="45" >End Color</th>
		</tr>
<%


for (int i = 0; i < typeCount; i++ ) {
    int j = i*2;
%>
<tr>
    <td><b><%=nodeTypes[i]%></b></td>
    <td>
    <div ID="swatch<%=j%>" class="swatch">
      <div class="border">
        <div ID="<%=nodeTypes[i] + "ColorStartID"%>" class="color" style="background-color: <%= latticeFactory.getProperties().getProperty(nodeTypes[i] + "ColorStart") %>;" onclick="setId('<%=nodeTypes[i] + "ColorStartID" %>');openChild('colorpicker2.html', 'Color Picker' , '<%=nodeTypes[i] + "ColorStartID"%>'); return false;">&nbsp;</div>
      </div>    
    </div>
     <input ID="<%= nodeTypes[i]+ "ColorStartValueID" %>" type="hidden" name="<%= nodeTypes[i]+ "ColorStart" %>" >
    </td>
    <td>
     <div ID="swatch<%=j+1%>" class="swatch">
      <div class="border">
        <div ID="<%=nodeTypes[i] + "ColorEndID"%>" class="color" style="background-color: <%=  latticeFactory.getProperties().getProperty(nodeTypes[i] + "ColorEnd") %>;" onclick="setId('<%=nodeTypes[i] + "ColorEndID"%>'); openChild('colorpicker2.html', 'Color Picker','<%=nodeTypes[i] + "ColorEndID"%>' ); return false;">&nbsp;</div>
      </div>    
    </div>
    
    <input ID="<%= nodeTypes[i]+ "ColorEndValueID" %>" type="hidden" name="<%= nodeTypes[i]+ "ColorEnd" %>" >
    </td>
</tr>
<%
}
%>
              </table>
            </td>
          </tr>
	  
	  <input type="hidden" name="idValue"></input>
	  
        </table>
	<br><br>
	<table cellpadding="0" cellspacing="0" border="0" >
        <tr>
          <td class="bord">
	      
              <table cellpadding="5" cellspacing="1" border="0" >
                <tr>
                  <td colspan="2">
                    <b>Preferences</b>
		  </td>
                </tr>
		<tr>
                  <th class="title">
                    Parameter
                  </th>
		  <th width = "40">
                    Value
                  </th>
		</tr>
	<%
    
        while (keys.hasNext())
	{
	  String key = keys.next().toString();
	  if ( (key.indexOf("ColorEnd") > 0) || (key.indexOf("ColorStart") > 0) || (key.indexOf("Style") > 0) ) continue;
	  
	%>
	<tr>
          <td><b><%=key%></b></td>
          <td> 
	         <input type="text" size="10" name="<%=key%>" value="<%=props.getProperty(key)%>">
		 </input>
          </td>
	  </tr>
    <%
    
        }
    %>
    <tr>
          <td><b>FontStyle</b></td>
          <td> 
	         <Select name="FontStyle">
		 <Option value="0">Normal</Option>
		 <Option value="1">Bold</Option>
		 <Option value="2">Italics</Option>
		 </Select>
          </td>
	  </tr>
	  
              </table>
            </td>
          </tr>
	  
	  
        </table>
        <br>
         <input type='submit' value='Update Preferences' ><br>
        <br>
         
      </form>
    </center>
  </body>
 </html>

